package com.w7vm.menuweb.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;

import com.w7vm.menuweb.entity.CardapioBuffetWeb;
import com.w7vm.menuweb.entity.ComposicaoCardBuffetWeb;


@Stateless
public class ComposicaoCardBuffetDAO extends GenericDAO<ComposicaoCardBuffetWeb> {

	
	@PersistenceContext(unitName = "MENUWEB-IAM-EJB")
	private EntityManager em;
	
	public ComposicaoCardBuffetDAO() {
		super(ComposicaoCardBuffetWeb.class);
	}


	@TransactionAttribute(TransactionAttributeType.REQUIRED)
	public void deleteCardapioBuffet(List<ComposicaoCardBuffetWeb> compCardBuffetEntity) {
		
		System.out.println("[IAM-EJB][deleteCardapioBuffet] :"+ compCardBuffetEntity);

		ComposicaoCardBuffetWeb composicaoBuffetObj = new ComposicaoCardBuffetWeb();
		CardapioBuffetWeb cardObj = new CardapioBuffetWeb();
		try{
			for(ComposicaoCardBuffetWeb cb : compCardBuffetEntity){
				System.out.println("[IAM-EJB][deleteCardapioBuffet] :"); //cb.getIdComposicaoCardBuffetWeb());

//				composicaoBuffetObj.setIdComposicaoCardBuffetWeb(119);
//				super.deletePK(composicaoBuffetObj.getIdComposicaoCardBuffetWeb(), ComposicaoCardBuffetWeb.class);
		
				
//				Map<String, Object> parameters = new HashMap<String, Object>();
//				int entityID = 119;
//				parameters.put("idComposicaoCardBuffetWeb", entityID);   
//				super.delete(ComposicaoCardBuffetWeb.DELETE_COMPOSICAO_CARBUFFET_BY_IDCARDAPIOBUFFET, parameters);

				
				composicaoBuffetObj = em.find(ComposicaoCardBuffetWeb.class,cb.getIdComposicaoCardBuffetWeb());
				
				System.out.println("[IAM-EJB][delete 2 ] :"+ composicaoBuffetObj.getIdComposicaoCardBuffetWeb());
				//System.out.println("[IAM-EJB][delete 2 ] :"+ composicaoBuffetObj.getCardapioBuffetWeb().getNomeBuffet());

				em.remove(composicaoBuffetObj);
				em.flush();
			}
			
		}catch (NoResultException e){
			System.err.println(e.getMessage());
		}

	}
	
}
